/**
 *  Created by clz on
 *  Function:
 *  Desc:
 */
import React, {Component} from 'react';
import {View, StyleSheet, AppState, Text} from 'react-native';

export default class AppState1 extends Component {
    constructor(props) {
        super(props);
        this.state = {
            currentAppState: AppState.currentState
        };
    }

    componentDidMount() {
        AppState.addEventListener('change', this._handleAppStateChange)
    }

    componentWillUnmount() {
        AppState.removeEventListener('change', this._handleAppStateChange)
    }

    _handleAppStateChange = (nextAppState) => {
        console.log(nextAppState);
        this.setState({
            currentAppState: nextAppState
        });
    };

    render() {
        return (
            <View>
                <Text>AppState:{this.state.currentAppState}</Text>
            </View>
        )
    }

}
